Python: bytes.decode で変換できない文字を制御するhandlerを作る
任意の文字に変換したり、追加のマッピングをしたい
ハンドラーを登録する
code:python
>> text = b'''\x1b$B='yu?@<R\x1b(B''' # 洲﨑神社 のJIS(ISO2022-JP)bytes
>> def handler(exc):
... return ('-', exc.end)
...
>> codecs.register_error('myerror', handler)
>> text.decode('iso2022jp', errors='myerror')
'洲-神社'
参考